<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>密码判断</title>
</head>
<body>
  <input type="password" name="password">
  <input type="password" name="confirm_password">
  <br>
  <span name="msg"></span>
  <script>
    function query(name){
       return document.querySelector(`[name='${name}']`)
    }
    console.log(query("password"))
    let inputs = document.querySelectorAll("[name='password'],[name='confirm_password']");
    console.log(inputs);
    [...inputs].map(item=>{
      item.addEventListener("keyup",()=>{
        let  msg = "";
        if(query("password").value  !== query("confirm_password").value || query("password").value.length<5){
          msg = "两次密码不一致或者密码长度小于五位"
        }
        query("msg").innerHTML = msg
      })
    })
  </script>
</body>
</html>